package utils;

import play.mvc.Http;

import java.util.Map;

/**
 * Created by zqx on 16/3/31.
 */
public class CookiesUtils {

    public static String getCookie(Http.Request request, String name) {
        Map cookies = request.current().cookies;
        //若cookies为空,遍历时会抛出空指针异常
        if(cookies != null && cookies.containsKey(name)) {
            Http.Cookie cook = (Http.Cookie) cookies.get(name);
            return cook.value;
        }
        return null;
    }

    public static void removeCookie(Http.Response response, String name) {
        response.removeCookie(name);
    }

    public static void addCookie(Http.Response response, String name, String value, int expiretime){
        response.setCookie(name, value, null, "/", expiretime, false);
    }
}
